package lexer

import (
	"fmt"
	"hsql/utils"
	"strings"
)

type Statement interface {
}

type StatementLexer func(tr *utils.TokenReader) (Statement, error)

var StatementMap = map[string]StatementLexer{
	"SELECT": SelectLexer,
}

func ParseStatement(tr *utils.TokenReader) (Statement, error) {
	token, err := tr.ReadToken()
	if err != nil {
		return nil, err
	}

	fn := StatementMap[strings.ToUpper(token)]
	if fn == nil {
		return nil, fmt.Errorf("token '%s' is not a keyword", token)
	}

	stat, err := fn(tr)
	if err != nil {
		return nil, err
	}

	return stat, nil
}
